#include <stdio.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#include <bios.h>
#include <dos.h>
#include <process.h>

void goto_xy (int x,int y) 
{ 
union REGS r; 
r.h.ah=2; 
r.h.bh=0; 
r.h.dh=(char) x; 
r.h.dl=(char) y; 
int86 (0x10,&r,&r); 
} 

get_key () 
{ 

union REGS r; 
r.h.ah=0; 
return int86 (0x16, &r, &r); 
} 


int wherex () 
{ 
int x; 
union REGS r; 
r.h.ah=3; 
r.h.bh=0; 
int86 (0x10, &r, &r); 
(char) x=r.h.dh; 
return x; 
} 


int wherey () 
{ 
int y; 
union REGS r; 
r.h.ah=3; 
r.h.bh=0; 
int86 (0x10, &r, &r); 
(char) y=r.h.dl; 
return y; 
} 


void write_video (int x, int y, char *p, int attrib) 
{ 
register int i; 
union REGS r; 
for(i=y;*p;i++) 
{ 
if(*p=='\n') 
{ 
goto_xy (x+1,2); 
break; 
} 
goto_xy (x,i); 
r.h.ah=9; 
r.h.bh=0; 
r.x.cx=1; 
r.h.al=*p++; 
r.h.bl=(char) attrib; 
int86 (0x10, &r, &r); 
} 
} 


void disptime (int x, int y) 
{ 
struct tm *newtime; 
time_t aclock; 
long startsec,currsec; 
int dqx,dqy; 
char sj[50], week[7]; 
time (&aclock); 
newtime=localtime (&aclock); 
startsec=newtime->tm_sec; 
switch (newtime->tm_wday) 
{ 
case 0:strcpy (week,"sunday"); break; 
case 1:strcpy (week,"monday"); break; 
case 2:strcpy (week,"tuesday"); break; 
case 3:strcpy (week,"wedensday"); break; 
case 4:strcpy (week,"thursday"); break; 
case 5:strcpy (week,"friday"); break; 
case 6:strcpy (week,"saturday"); break; 
} 
while(!kbhit ()) 
{ 
time (&aclock); 
newtime=localtime (&aclock); 
sprintf (sj,"%d.%2d.%2d.%s %d:%2d:%2d", 
newtime->tm_year+1900, 
newtime->tm_mon+1, 
newtime->tm_mday, 
week, 
newtime->tm_hour, 
newtime->tm_min, 
newtime->tm_sec); 
currsec=newtime->tm_sec; 
if(startsec!=currsec) 
{ 
dqx=wherex (); 
dqy=wherey (); 
write_video (x, y, sj, 0x0a); 
goto_xy (dqx, dqy); 
return; 
} 
} 
} 


main () 
{ 
union inkey 
{ 
char ch[2]; 
int i; 
}c; 
for( ; ; ) 
{ 
for( ; ;) 
{ 
if (kbhit ()) 
{ 
c.i=get_key (); 
break; 
}
disptime (0 ,54); 
if (c.ch[0]==27) 
exit (0); 
} 
} 
}